home *** CD-ROM | disk | FTP | other *** search
/ NOVA - For the NeXT Workstation / NOVA - For the NeXT Workstation.iso / Documents / NeXTAnswers / objc.605 < prev    next >
Text File  |  1992-02-06  |  2KB  |  63 lines

  1. {\rtf0\ansi{\fonttbl\f0\fnil Times-Roman;\f1\fmodern Courier;}
  2. \paperw11440
  3. \paperh9000
  4. \margl120
  5. \margr120
  6. {\colortbl\red0\green0\blue0;}
  7. \pard\tx960\tx1920\tx2880\tx3840\tx4800\tx5760\tx6720\tx7680\tx8640\tx9600\f0\b0\i0\ul0\fs28 @defs instance variables\
  8.     \
  9. Q:  I'm writing a library and I really really really really need to get at the mode of a Matrix.  Because this code is a stand-alone product and will integrate into applications written by others, I can't get at this information by subclassing Matrix or doing a poseAs: for the Matrix class.  Is there a way to get this information?\
  10. \
  11. Or, more simply put:\
  12. Q:  How can I get at the private instance variables of a class?\
  13.  
  14. \i     \
  15.  
  16. \i0 A:  There is a construct which allows you to do this.  We don't encourage it and it's not really documented.  But if you really really must, then you can use the @defs construct.  @defs allows you to essentially import all the instance variables of a given class into a structure local to your application.\
  17. \
  18. Here is an example of how to get at the mode of a Matrix:\
  19. \
  20.  
  21. \f1\fs24 struct    InternalDetails\
  22. \{\
  23.     @defs(Matrix);\
  24. \};\
  25. \
  26. struct InternalDetails  *matrixGoodies;\
  27. \
  28. matrixGoodies = (struct InternalDetails *)[Matrix new];\
  29. if (matrixGoodies->mFlags.radioMode == ...)\
  30.  
  31. \fs20 \
  32.  
  33. \f0\fs28 \
  34.  
  35. \b Important Note:
  36. \b0   Never use this technique to set or look at the values of instance variables whose names start with an underline.  The contents of those variables are private and do change between releases.  It's OK to use  \
  37. \
  38.     
  39. \f1\fs24 @defs
  40. \f0\fs28    \
  41. \
  42. or   \
  43. \
  44.     
  45. \f1\fs24 Matrix *m
  46. \f0\fs28 ; \
  47. \
  48. type constructs to get at the "public" private variables, but NOT at the "private" private variables.\
  49. \
  50. This solution should only be used as a last resort.\
  51. \
  52. QA605                \
  53.  
  54. \gray333 \
  55.  
  56. \gray0 Valid for 1.0\
  57.  
  58. \fc0 Valid for 2.0\
  59.  
  60. \gray333 \
  61.  
  62.  
  63.